<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('访客预约列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>访客姓名：</label>
                                <input type="text" name="visitorName" placeholder="访客姓名"/>
                            </li>
                            <li>
                                <label>访客证号：</label>
                                <input type="text" name="visitorIdcard" placeholder="访客身份证号"/>
                            </li>
                            <li>
                                <label>被访人：</label>
                                <input type="text" name="visitedIdcard" placeholder="被访人姓名"/>
                            </li>
                            <li>
                                审批状态：<select name="approvalStatus" th:with="type=${@dict.getType('approval_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                            </li>

                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "visitor/appointment";
        var datas = [[${@dict.getType('approval_status')}]];

        $(function() {
            var options = {
                url: prefix + "/toApprovalList",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "访客预约记录",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'unionid',
                    title: '预约用户unionid',
                    visible: false
                },
                {
                    field: 'visitorName',
                    title: '访客姓名'
                },
                {
                    field: 'visitorIdcard',
                    title: '访客身份证号'
                },
                {
                    field: 'visitorPhone',
                    title: '访客手机号'
                },
                {
                    field: 'visitedIdcard',
                    title: '被访人身份证号',
                    visible: false
                },
                {
                    field: 'visitedDept',
                    title: '访问部门'
                },
                {
                    field: 'visitedDays',
                    title: '访问天数'
                },
                {
                    field: 'eta',
                    title: '预计到达时间'
                },
                {
                    field: 'etd',
                    title: '预计离开时间',
                    visible: false
                },
                {
                    field: 'approvalStatus',
                    title: '审批状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'enterCode',
                    title: '进入码'
                },
                {
                    field: 'leaveCode',
                    title: '离开码'
                },
                {
                    field: 'reason',
                    title: '事由'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        var disabled = "disabled";
                        if(row.approvalStatus == 'T'){
                            disabled = '';
                        }
                        actions.push('<a class="btn btn-success btn-xs '+disabled+' " href="javascript:void(0)" onclick="accept(\'' + row.id + '\')"><i class="fa fa-edit"></i>同意</a> ');
                        actions.push('<a class="btn btn-danger btn-xs  '+disabled+' " href="javascript:void(0)" onclick="reject(\'' + row.id + '\')"><i class="fa fa-remove"></i>驳回</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function accept(id){
            approval(id,'A');
        }
        function reject(id){
            approval(id,'R');
        }
        function approval(id,status) {
            var data = "id="+id+"&approvalStatus="+status;
            $.operate.save(prefix + "/approval", data);
        }
    </script>
</body>
</html>